﻿using System;
namespace Producers.Ehr.Xtee.Riik.Ee.Producer.Ehr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="EN_OtsiAadressiAdr_response", Namespace="http://producers.ehr.xtee.riik.ee/producer/ehr", Target=typeof(ENOtsiAadressiAdrResponse))]
    public class ENOtsiAadressiAdrResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IENOtsiAadressiAdrResponse clazz;
        
        public ENOtsiAadressiAdrResponseSerializer(IENOtsiAadressiAdrResponse clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("EN_OtsiAadressiAdr");
            if (clazz.ENOtsiAadressiAdr!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute(">>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress", "http://producers.ehr.xtee.riik.ee/producer/ehr", clazz.ENOtsiAadressiAdr.Count);
                for (int x = 0; ((clazz.ENOtsiAadressiAdr != null) 
                            && (x < clazz.ENOtsiAadressiAdr.Count)); x = (x + 1)) {
                    if (clazz.ENOtsiAadressiAdr[x]!=null) {
                        Writer.WriteStartElement("aadress");
                        global::Xtee.Core.SerializationMetadata metaENOtsiAadressiAdr = this.GetMetaData(clazz.ENOtsiAadressiAdr[x]);
                        Writer.WriteTypeAttribute(metaENOtsiAadressiAdr.TypeQualifiedName.Namespace, metaENOtsiAadressiAdr.TypeQualifiedName.Name);
                        metaENOtsiAadressiAdr.NewSerializer(clazz.ENOtsiAadressiAdr[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : ENOtsiAadressiAdr");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="EN_OtsiAadressiAdr") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr");
                }
                clazz.ENOtsiAadressiAdr = new System.Collections.Generic.List<ENOtsiAadressiAdrResponse.IENOtsiAadressiAdrType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("EN_OtsiAadressiAdr");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "aadress")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress");
                        }
                        global::Xtee.Core.SerializationMetadata metaENOtsiAadressiAdr = this.GetMetaData<ENOtsiAadressiAdrResponse.IENOtsiAadressiAdrType>(Reader, ">>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress", "http://producers.ehr.xtee.riik.ee/producer/ehr");
                        ENOtsiAadressiAdrResponse.IENOtsiAadressiAdrType item = metaENOtsiAadressiAdr.NewEntity<ENOtsiAadressiAdrResponse.IENOtsiAadressiAdrType>();
                        clazz.ENOtsiAadressiAdr.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("aadress");
                            metaENOtsiAadressiAdr.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr", Reader.LocalName);
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress", Namespace="http://producers.ehr.xtee.riik.ee/producer/ehr", Target=typeof(ENOtsiAadressiAdrResponse.ENOtsiAadressiAdrType))]
        public class ENOtsiAadressiAdrTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected ENOtsiAadressiAdrResponse.IENOtsiAadressiAdrType clazz;
            
            public ENOtsiAadressiAdrTypeSerializer(ENOtsiAadressiAdrResponse.IENOtsiAadressiAdrType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                if (clazz.Tase3Nimetus!=null) {
                    Writer.WriteStartElement("tase3_nimetus");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tase3Nimetus))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Aadress!=null) {
                    Writer.WriteStartElement("aadress");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Aadress))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Tase1Id!=null) {
                    Writer.WriteStartElement("tase1_id");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tase1Id))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Tase2Nimetus!=null) {
                    Writer.WriteStartElement("tase2_nimetus");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tase2Nimetus))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Tase2Id!=null) {
                    Writer.WriteStartElement("tase2_id");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tase2Id))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Tase3Id!=null) {
                    Writer.WriteStartElement("tase3_id");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tase3Id))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Id!=null) {
                    Writer.WriteStartElement("id");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.Id))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Tase4Id!=null) {
                    Writer.WriteStartElement("tase4_id");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tase4Id))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Tase5Nimetus!=null) {
                    Writer.WriteStartElement("tase5_nimetus");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tase5Nimetus))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Tase5Id!=null) {
                    Writer.WriteStartElement("tase5_id");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tase5Id))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Tase6Nimetus!=null) {
                    Writer.WriteStartElement("tase6_nimetus");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tase6Nimetus))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Tase6Id!=null) {
                    Writer.WriteStartElement("tase6_id");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tase6Id))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Tase7Nimetus!=null) {
                    Writer.WriteStartElement("tase7_nimetus");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tase7Nimetus))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Tase7Id!=null) {
                    Writer.WriteStartElement("tase7_id");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tase7Id))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Tekst!=null) {
                    Writer.WriteStartElement("tekst");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tekst))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Olek!=null) {
                    Writer.WriteStartElement("olek");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Olek))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.AadressTekstina!=null) {
                    Writer.WriteStartElement("aadress_tekstina");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.AadressTekstina))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Tase1Nimetus!=null) {
                    Writer.WriteStartElement("tase1_nimetus");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tase1Nimetus))).ToString());
                    Writer.WriteEndElement();
                }
                if (clazz.Tase4Nimetus!=null) {
                    Writer.WriteStartElement("tase4_nimetus");
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tase4Nimetus))).ToString());
                    Writer.WriteEndElement();
                }
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="tase3_nimetus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress>tase3_nimetus");
                    }
                    clazz.Tase3Nimetus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tase3_nimetus")).Value;
                }
                if (Reader.LocalName=="aadress") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress>aadress");
                    }
                    clazz.Aadress = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("aadress")).Value;
                }
                if (Reader.LocalName=="tase1_id") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress>tase1_id");
                    }
                    clazz.Tase1Id = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tase1_id")).Value;
                }
                if (Reader.LocalName=="tase2_nimetus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress>tase2_nimetus");
                    }
                    clazz.Tase2Nimetus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tase2_nimetus")).Value;
                }
                if (Reader.LocalName=="tase2_id") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress>tase2_id");
                    }
                    clazz.Tase2Id = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tase2_id")).Value;
                }
                if (Reader.LocalName=="tase3_id") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress>tase3_id");
                    }
                    clazz.Tase3Id = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tase3_id")).Value;
                }
                if (Reader.LocalName=="id") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress>id");
                    }
                    clazz.Id = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("id")).Value;
                }
                if (Reader.LocalName=="tase4_id") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress>tase4_id");
                    }
                    clazz.Tase4Id = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tase4_id")).Value;
                }
                if (Reader.LocalName=="tase5_nimetus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress>tase5_nimetus");
                    }
                    clazz.Tase5Nimetus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tase5_nimetus")).Value;
                }
                if (Reader.LocalName=="tase5_id") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress>tase5_id");
                    }
                    clazz.Tase5Id = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tase5_id")).Value;
                }
                if (Reader.LocalName=="tase6_nimetus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress>tase6_nimetus");
                    }
                    clazz.Tase6Nimetus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tase6_nimetus")).Value;
                }
                if (Reader.LocalName=="tase6_id") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress>tase6_id");
                    }
                    clazz.Tase6Id = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tase6_id")).Value;
                }
                if (Reader.LocalName=="tase7_nimetus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress>tase7_nimetus");
                    }
                    clazz.Tase7Nimetus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tase7_nimetus")).Value;
                }
                if (Reader.LocalName=="tase7_id") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress>tase7_id");
                    }
                    clazz.Tase7Id = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tase7_id")).Value;
                }
                if (Reader.LocalName=="tekst") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress>tekst");
                    }
                    clazz.Tekst = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tekst")).Value;
                }
                if (Reader.LocalName=="olek") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress>olek");
                    }
                    clazz.Olek = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("olek")).Value;
                }
                if (Reader.LocalName=="aadress_tekstina") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress>aadress_tekstina");
                    }
                    clazz.AadressTekstina = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("aadress_tekstina")).Value;
                }
                if (Reader.LocalName=="tase1_nimetus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress>tase1_nimetus");
                    }
                    clazz.Tase1Nimetus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tase1_nimetus")).Value;
                }
                if (Reader.LocalName=="tase4_nimetus") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>EN_OtsiAadressiAdr_response>EN_OtsiAadressiAdr>aadress>tase4_nimetus");
                    }
                    clazz.Tase4Nimetus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tase4_nimetus")).Value;
                }
            }
        }
    }
}
